<template>
  <main>
    <div class="form-title">
      <p class="title">日志管理</p>
      <div class="form-input"> <label>日志状态</label><a-switch v-model:checked="status" @change="handleChangeStatus" /> </div>
    </div>
    <div class="form-title form-title1">
      <div class="title">仪表盘管理</div>
      <a-button class="common-btn" preIcon="ant-design:plus-outlined" @click="handleAdd">新增</a-button>
    </div>
    <section class="card-list">
      <div class="card" v-for="(item, index) in panelList" :key="index">
        <div class="card-head">
          <img
            src=""
            class="card-image"
          />
          <div class="btns">
            <img
              src=""
              class="row-btn-img"
              @click="handleEdit(item)"
            />
            <img
              src=""
              class="row-btn-img"
              @click="handleDetail(item)"
            />
            <a-popconfirm title="您确定要删除吗？" ok-text="确定" cancel-text="取消" @confirm="handleDelete(item)">
              <img
                src=""
                class="row-btn-img"
              />
            </a-popconfirm>
          </div>
        </div>
        <p class="card-name">{{ item.desc }}</p>
        <p class="card-row"> {{ item.grafanaUrl }} </p>
      </div>
    </section>
  </main>
  <ConfigModal @register="registerModal" @success="reload" />
</template>
<script lang="ts" setup>
  import { ref, reactive } from 'vue';
  import ConfigModal from './ConfigModal.vue';
  import { deleteRequest } from './config.api';
  import { useModal } from '/@/components/Modal';
  const [registerModal, { openModal }] = useModal();
  const status = ref<boolean>(false);
  const panelList = reactive([
    {
      desc: '表盘',
      grafanaUrl: 'http://demo.fluxmq.com/#/system/setting',
      id: 'c3568dfee5a24dd8b7d549690fca09a7',
      type: 'grafana',
    },
  ]);
  function handleChangeStatus() {}
  function handleAdd() {
    openModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  async function handleDelete(record) {
    await deleteRequest({ id: record.id });
  }
  function handleEdit(record) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: true,
    });
  }
  function handleDetail(record) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
  }
</script>
<style lang="less" scoped>
  p {
    margin-bottom: 0;
  }
  main {
    padding: 20px;
    background-color: #fff;
    box-shadow: 0 0 18px 0 rgba(0, 0, 0, 0.06);
    border-radius: 8px;
  }
  .form-title1 {
    display: flex;
    align-items: center;
    margin: 16px 0;
  }
  .form-title .form-input {
    padding: 8px 12px;
    width: 168px;
    flex: 0 0 168px;
    background: #fff;
    border-radius: 18px;
    border: 1px solid #b3bac3;
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
  }
  .form-input label {
    font-size: 13px;
    font-weight: 400;
    color: #b3bac3;
    line-height: 20px;
  }
  .form-title .title {
    font-size: 15px;
    text-align: left;
    height: 34px;
    line-height: 34px;
    font-weight: 600;
    color: #0b1e42;
  }
  .common-btn {
    background: linear-gradient(144deg, rgba(18, 76, 255, 0.12), rgba(67, 147, 255, 0.12));
    border-radius: 18px;
    font-size: 13px;
    color: #1d6bff;
    margin: 0 16px;
    border: none;
    cursor: pointer;
  }
  .card-list {
    display: flex;
    flex-wrap: wrap;
  }
  .card-list .card {
    width: 0;
    flex: 0 0 390px;
    height: 150px;
    background: #f5f8fa;
    border-radius: 8px;
    padding: 16px;
    position: relative;
    margin: 0 16px 16px 0;
  }
  .card-list .card .card-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
    font-weight: 700;
  }
  .card-list .card .card-head .card-image {
    height: 55px;
    flex: 0 0 55px;
    border-radius: 4px;
  }
  .card-list .card .card-head .btns .row-btn-img {
    width: 24px;
    height: 24px;
    margin-left: 8px;
    cursor: pointer;
    margin-top: 17px;
  }
  .card-list .card .card-name {
    font-size: 15px;
    font-weight: 600;
    color: #0b1e42;
    line-height: 22px;
    margin-top: 9px;
  }
  .card-list .card .card-row {
    margin-top: 6px;
    font-size: 13px;
    font-weight: 400;
    color: #788aa0;
    line-height: 18px;
  }
</style>
